package com.working.project.ui.main

import android.view.LayoutInflater
import android.view.ViewGroup
import com.working.libbase.base.WebViewActivity
import com.working.libbase.model.ArticleResponse
import com.working.libcommon.adapter.BasePagingAdapter
import com.working.libcommon.adapter.BaseViewHolder
import com.working.libcommon.adapter.PagingDataSource
import com.working.libcommon.exts.onClick
import com.working.project.databinding.ProjectItemProjectBinding

class ProjectAdapter(override val dataSource: PagingDataSource<ArticleResponse>) :
    BasePagingAdapter<ArticleResponse, ProjectAdapter.ViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            ProjectItemProjectBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        )
    }

    class ViewHolder(private val binding: ProjectItemProjectBinding) :
        BaseViewHolder<ArticleResponse>(binding.root) {
        override fun bindData(data: ArticleResponse, position: Int) {
            binding.item = data
            binding.root.onClick {
                WebViewActivity.start(data.titleImpl(), data.link)
            }
            binding.executePendingBindings()
        }
    }
}